package com.hc.sss.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.BuyMapper;
import com.hc.sss.pojo.Buy;
import com.hc.sss.pojo.Send;
import com.hc.sss.service.BuyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

@Service
public class BuyServiceImpl implements BuyService {

    @Resource
    private BuyMapper buyMapper;

    @Override
    public int insertBuy(Map buyMap) {
        return buyMapper.insertBuy(buyMap);
    }

	@Override
	public ResultMap<Buy> findListBuyByPublish(Map<String, Object> param) {
		ResultMap<Buy> resultMap = new ResultMap<Buy>();
		Integer page = 1;
		Integer limit = 5;
		if (param.get("page") != null && !"".equals(param.get("page"))) {
			page = Integer.valueOf(param.get("page").toString());
		}
		if (param.get("limit") != null && !"".equals(param.get("limit"))) {
			limit = Integer.valueOf(param.get("limit").toString());
		}
		PageHelper.startPage(page, limit);
		List<Buy> list = buyMapper.findListBuyByPublish(param);
		PageInfo<Buy> info = new PageInfo<>(list);
		resultMap.setData(list);
		resultMap.setCount((int)info.getTotal());
		return resultMap;
	}
}
